; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=guard-widening -S < %s | FileCheck %s

define ptr @test(i1 %cond, ptr %p) {
; CHECK-LABEL: @test(
; CHECK-NEXT:  bb:
; CHECK-NEXT:    [[VAR:%.*]] = call i1 @llvm.experimental.widenable.condition()
; CHECK-NEXT:    [[VAR2:%.*]] = call i1 @llvm.experimental.widenable.condition()
; CHECK-NEXT:    [[VAR3:%.*]] = and i1 [[COND:%.*]], [[VAR2]]
; CHECK-NEXT:    br label [[BB4:%.*]]
; CHECK:       bb4:
; CHECK-NEXT:    [[VAR5:%.*]] = load atomic i32, ptr [[P:%.*]] unordered, align 8
; CHECK-NEXT:    [[VAR6:%.*]] = icmp ugt i32 [[VAR5]], 0
; CHECK-NEXT:    [[VAR7:%.*]] = and i1 [[VAR6]], [[VAR]]
; CHECK-NEXT:    br i1 [[VAR7]], label [[BB10:%.*]], label [[BB8:%.*]]
; CHECK:       bb8:
; CHECK-NEXT:    [[VAR9:%.*]] = call ptr (...) @llvm.experimental.deoptimize.p0(i32 13) [ "deopt"(i32 0) ]
; CHECK-NEXT:    ret ptr [[VAR9]]
; CHECK:       bb10:
; CHECK-NEXT:    br i1 [[VAR3]], label [[BB13:%.*]], label [[BB11:%.*]]
; CHECK:       bb11:
; CHECK-NEXT:    [[VAR12:%.*]] = call ptr (...) @llvm.experimental.deoptimize.p0(i32 13) [ "deopt"(i32 1) ]
; CHECK-NEXT:    ret ptr [[VAR12]]
; CHECK:       bb13:
; CHECK-NEXT:    unreachable
;
bb:
  %var = call i1 @llvm.experimental.widenable.condition()
  %var2 = call i1 @llvm.experimental.widenable.condition()
  %var3 = and i1 %cond, %var2
  br label %bb4

bb4:                                              ; preds = %bb
  %var5 = load atomic i32, ptr %p unordered, align 8
  %var6 = icmp ugt i32 %var5, 0
  %var7 = and i1 %var6, %var
  br i1 %var7, label %bb10, label %bb8

bb8:                                              ; preds = %bb4
  %var9 = call ptr (...) @llvm.experimental.deoptimize.p0(i32 13) [ "deopt"(i32 0) ]
  ret ptr %var9

bb10:                                             ; preds = %bb4
  br i1 %var3, label %bb13, label %bb11

bb11:                                             ; preds = %bb10
  %var12 = call ptr (...) @llvm.experimental.deoptimize.p0(i32 13) [ "deopt"(i32 1) ]
  ret ptr %var12

bb13:                                             ; preds = %bb10
  unreachable
}

declare ptr @llvm.experimental.deoptimize.p0(...)

declare i1 @llvm.experimental.widenable.condition()
